#include "AnaDef.h"
#include "AnaAliDef.h"
#include "AliAnalysisTaskSE.h"
#include "AliAnalysisAlien.h"

class AliAnalysisAlien;

Int_t fID = -999;
TString fGridMode;
TString fProd;
Bool_t fkTest = kTRUE;
Int_t fkMC   = -999;
Int_t fkPbPb = -999;

//=====

//Warning in <AliAnalysisAlien::SetRunMode>: Run mode "init" not known. Supported modes: "full", "test", "offline", "submit" and "merge"
//Warning in <AliAnalysisAlien::SetRunMode>: Run mode set to FULL
//I-AliAnalysisAlien::StartAnalysis: 
//#### STARTING AN ALIEN SHELL FOR YOU. EXIT WHEN YOUR JOB  HAS FINISHED. ####    
//You may exit at any time and terminate the job later using the option <terminate>    
//

void Load();
void submit(const char *taskname);
AliAnalysisGrid* CreateAlienHandler(const char *taskname);

Int_t runPlugIn(const Int_t ktest, const char * gmode)
{
  fkTest = ktest;
  fGridMode = gmode;

  if(fGridMode!="full" && fGridMode!="merge" && fGridMode!="terminate"){
    printf("wrong gridmode %s\n", fGridMode.Data()); return 1;
  }

  //==========================================================================
  //            set from pwd
  //==========================================================================
  
  TString pwd = gSystem->pwd();

  //set production
  fProd="";
  if(pwd.Contains("10e")) fProd += "  10e";
  if(pwd.Contains("10h")) fProd += "  10h";
  if(pwd.Contains("11a")) fProd += "  11a";
  if(pwd.Contains("11h")) fProd += "  11h";
  if(pwd.Contains("12f")) fProd += "  12f";
  if(pwd.Contains("12g")) fProd += "  12g";
  if(pwd.Contains("MC"))  fProd += "MC";
  //ensure only one period is selected
  if(fProd.Length()==0 || fProd.Length()>7){
    printf("pwd error! no production %s %s\n", pwd.Data(), fProd.Data()); return 1;
  }
  fProd.ReplaceAll(" ","");

  //set ID
  pwd.ReplaceAll("ID","@");
  const Int_t kk = pwd.First("@");
  pwd=pwd(kk+1,10);
  fID = -999;
  if(kk>0){
    fID=atoi(pwd.Data());
  }
  if(fID<=0){
    printf("fID<=0!! %d %s %s\n", fID, gSystem->pwd(), pwd.Data()); return 1;
  }

  //==========================================================================
  //            further set
  //==========================================================================

  //set kMC
  fkMC = fProd.Contains("MC");

  //set kPbPb
  fkPbPb = -999;
  if(fProd.Contains("10h") || fProd.Contains("11h")){
    fkPbPb = 1;
  }
  else if(fProd.Contains("10e") || fProd.Contains("11a") || fProd.Contains("12f") || fProd.Contains("12g")){
    fkPbPb = 0;
  }

  if(fkPbPb<0){
    printf("kProd error !! %s %d\n", fProd.Data(), fkPbPb); return 1;
  }
  //=========

  const TString taskname = "pkRaa";
  gSystem->Exec(Form("ln -s ../AliAnalysisTask%s.h",taskname.Data()));
  gSystem->Exec(Form("ln -s ../AliAnalysisTask%s.cxx",taskname.Data()));

  submit(taskname);
  return 0;
}

void submit(const char *taskname)
{
  Load();
  
  printf("************************\n\n");
  printf("check \nkTest %d \nGridMode %s \nProd %s \nID %d \nkMC %d \nkPbPb %d\n", fkTest, fGridMode.Data(), fProd.Data(), fID, fkMC, fkPbPb);
  printf("************************\n\n");
  
  AliLog::SetGlobalLogLevel(AliLog::kError);

  AliAnalysisManager* mgr = new AliAnalysisManager(Form("%sManager",taskname));
  mgr->SetGridHandler(CreateAlienHandler(taskname));
  mgr->SetInputEventHandler(new AliESDInputHandler());

  //this is for sure needed! -->
  gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
  Long_t r = gROOT->ProcessLine(Form("AddTaskPhysicsSelection(%d)", fkMC));
  AliPhysicsSelectionTask *physSelTask = reinterpret_cast<AliPhysicsSelectionTask*>(r);
  if(!physSelTask) { printf("no physSelTask"); exit(1); }

  if(fkPbPb){
    gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskCentrality.C");
    r = gROOT->ProcessLine("AddTaskCentrality()");
    AliCentralitySelectionTask *taskCentrality = reinterpret_cast<AliCentralitySelectionTask*>(r);
    if(!taskCentrality) { printf("no taskCentrality"); exit(1); }
    if(fkMC){
      taskCentrality->SetMCInput(); 
    }
  }

  if(fkMC){
    AliMCEventHandler* mcHandler = new AliMCEventHandler();
    mgr->SetMCtruthEventHandler(mcHandler);
    //TR track reference
    mcHandler->SetReadTR(0); 
  }
  //<--

  gROOT->LoadMacro(Form("AliAnalysisTask%s.cxx+g", taskname));        
  r = gROOT->ProcessLine(Form("new AliAnalysisTask%s",taskname));
  AliAnalysisTaskSE* task = reinterpret_cast<AliAnalysisTaskSE*>(r);

  //needed for ESD and MC
  task->SelectCollisionCandidates(AliVEvent::kMB);

  mgr->AddTask(task);
        
  AliAnalysisDataContainer *cinput  = mgr->GetCommonInputContainer();
  mgr->ConnectInput(task,  0, cinput );
  
  const TString foutname=Form("xlu_%s.root",taskname);
  AliAnalysisDataContainer *outlist1 = mgr->CreateContainer("xlu_tree",            TTree::Class(), AliAnalysisManager::kOutputContainer,foutname);
  AliAnalysisDataContainer *outlist2 = mgr->CreateContainer("xlu_list",            TList::Class(), AliAnalysisManager::kOutputContainer,foutname);
  AliAnalysisDataContainer *outlist3 = mgr->CreateContainer("xlu_mctree",          TTree::Class(), AliAnalysisManager::kOutputContainer,foutname);
  
  //in AnalysisTaskSE, slot 0 reserved, must start from 1
  task->ConnectOutput(1, outlist1);
  task->ConnectOutput(2, outlist2);
  task->ConnectOutput(3, outlist3);

  mgr->SetDebugLevel(2);
  if (!mgr->InitAnalysis()) return;
  mgr->PrintStatus();
  
  mgr->StartAnalysis("grid");
}

void Set10hESD(AliAnalysisAlien *plugin)
{
  plugin->SetGridDataDir("/alice/data/2010/LHC10h");
  
  //must be called before AddRunNumber!!
  plugin->SetRunPrefix("000");   // real data
  
  if(fkTest){
    plugin->SetDataPattern("ESDs/pass2/10000139037001.10/AliESDs.root");
    plugin->AddRunNumber(139037);
    
    plugin->SetSplitMaxInputFileNumber(1);
    plugin->SetNrunsPerMaster(200);
  }
  else {	
    plugin->SetDataPattern("ESDs/pass2/10000*.*/AliESDs.root");
    //http://alimonitor.cern.ch/configuration/index.jsp?partition=LHC10h&pass=2&s=%BB&raw_run=&filling_scheme=&filling_config=&fillno=&energy=&intensity_per_bunch=&mu=&interacting_bunches=&noninteracting_bunches_beam_1=&noninteracting_bunches_beam_2=&interaction_trigger=&rate=&beam_empty_trigger=&empty_empty_trigger=&muon_trigger=&high_multiplicity_trigger=&emcal_trigger=&calibration_trigger=&quality=1&muon_quality=&comment=&field=&det_aco=&det_emc=&det_fmd=&det_hlt=&det_hmp=&det_mch=&det_mtr=&det_phs=&det_pmd=&det_spd=&det_sdd=&det_ssd=&det_tof=&det_tpc=&det_trd=&det_t00=&det_v00=&det_zdc=&hlt_mode=&changedon=
    //93 runs
    const Int_t runlist[]={139510, 139507, 139505, 139503, 139465, 139438, 139437, 139360, 139329, 139328, 139314, 139310, 139309, 139173, 139107, 139105, 139038, 139037, 139036, 139029, 139028, 138872, 138871, 138870, 138837, 138732, 138730, 138666, 138662, 138653, 138652, 138638, 138624, 138621, 138583, 138582, 138579, 138578, 138534, 138469, 138442, 138439, 138438, 138396, 138364, 138275, 138225, 138201, 138197, 138192, 138190, 137848, 137844, 137752, 137751, 137724, 137722, 137718, 137704, 137693, 137692, 137691, 137686, 137685, 137639, 137638, 137608, 137595, 137549, 137546, 137544, 137541, 137539, 137531, 137530, 137443, 137441, 137440, 137439, 137434, 137432, 137431, 137430, 137366, 137243, 137236, 137235, 137232, 137231, 137230, 137162, 137161, 137135};
    
    const Int_t nrun = sizeof(runlist)/sizeof(Int_t);
    printf("nrun: %d\n", nrun);
    for (Int_t ind=0; ind<nrun; ind++) {
      plugin->AddRunNumber(runlist[ind]);
    }

    plugin->SetSplitMaxInputFileNumber(100);
    plugin->SetNrunsPerMaster(50);
  }
}

void Set10hMCESD(AliAnalysisAlien *plugin)
{
  plugin->SetGridDataDir("/alice/sim/LHC11a10a_bis");
  
  //must be called before AddRunNumber!!
  //plugin->SetRunPrefix("000");   // real data
  
  if(fkTest){
    plugin->SetDataPattern("001/AliESDs.root");
    plugin->AddRunNumber(137692);
    
    plugin->SetSplitMaxInputFileNumber(1);
    plugin->SetNrunsPerMaster(200);
  }
  else {	
    printf("10hMC no ktest=0 mode!\n");exit(1);
  }
}

void Set11hESD(AliAnalysisAlien *plugin)
{
  plugin->SetGridDataDir("/alice/data/2011/LHC11h_2");
  
  //must be called before AddRunNumber!!
  plugin->SetRunPrefix("000");   // real data
  
  if(fkTest){
    printf("11h no ktest=1 mode!!\n"); exit(1);
  }
  else {	
    plugin->SetDataPattern("ESDs/pass2/11000*.*/AliESDs.root");
    //108 runs
    const Int_t runlist[]={170593, 170572, 170388, 170387, 170315, 170313, 170312, 170311, 170309, 170308, 170306, 170270, 170269, 170268, 170230, 170228, 170207, 170204, 170203, 170193, 170163, 170159, 170155, 170091, 170089, 170088, 170085, 170084, 170083, 170081, 170040, 170027, 169965, 169923, 169859, 169858, 169855, 169846, 169838, 169837, 169835, 169591, 169590, 169588, 169587, 169586, 169557, 169555, 169554, 169553, 169550, 169515, 169512, 169506, 169504, 169498, 169475, 169420, 169419, 169418, 169417, 169415, 169411, 169238, 169167, 169160, 169156, 169148, 169145, 169144, 169138, 169099, 169094, 169091, 169045, 169044, 169040, 169035, 168992, 168988, 168826, 168777, 168514, 168512, 168511, 168467, 168464, 168460, 168458, 168362, 168361, 168342, 168341, 168325, 168322, 168311, 168310, 168115, 168108, 168107, 168105, 168076, 168069, 167988, 167987, 167985, 167920, 167915};
    
    const Int_t nrun = sizeof(runlist)/sizeof(Int_t);
    printf("nrun: %d\n", nrun);
    for (Int_t ind=0; ind<nrun; ind++) {
      plugin->AddRunNumber(runlist[ind]);
    }

    plugin->SetSplitMaxInputFileNumber(100);
    plugin->SetNrunsPerMaster(1);
  }
}

void Set12fESD(AliAnalysisAlien *plugin)
{
  plugin->SetGridDataDir("/alice/data/2012/LHC12f");
  //must be called before AddRunNumber!!
  plugin->SetRunPrefix("000");   // real data

  if(fkTest){
    ///alice/data/2012/LHC12f/000186668/cpass1/12000186668062.17/AliESDs_Barrel.root
    plugin->SetDataPattern("cpass1/12000186668062.17/AliESDs_Barrel.root");
    plugin->AddRunNumber(186668);
    plugin->SetNrunsPerMaster(20); 
    plugin->SetSplitMaxInputFileNumber(100);
  }
  else {	
    plugin->SetDataPattern("cpass1/12000*.*/AliESDs_Barrel.root");
 
    //http://alimonitor.cern.ch/configuration/index.jsp?partition=LHC12f&pass=4&raw_run=&filling_scheme=&filling_config=&fillno=&energy=&intensity_per_bunch=&mu=&interacting_bunches=&noninteracting_bunches_beam_1=&noninteracting_bunches_beam_2=&interaction_trigger=&rate=&beam_empty_trigger=&empty_empty_trigger=&muon_trigger=&high_multiplicity_trigger=&emcal_trigger=&calibration_trigger=&quality=&muon_quality=&comment=&field=&det_aco=&det_emc=&det_fmd=&det_hlt=&det_hmp=&det_mch=&det_mtr=&det_phs=&det_pmd=&det_spd=&det_sdd=&det_ssd=&det_tof=&det_tpc=&det_trd=&det_t00=&det_v00=&det_zdc=&hlt_mode=&changedon=
    //134 runs
    const Int_t runlist[]={188123, 188108, 188101, 188093, 188088, 188071, 188029, 188028, 188027, 188025, 188021, 188018, 187990, 187986, 187875, 187849, 187848, 187843, 187820, 187796, 187791, 187785, 187783, 187780, 187753, 187749, 187744, 187739, 187736, 187698, 187697, 187695, 187691, 187656, 187654, 187633, 187627, 187624, 187623, 187618, 187562, 187561, 187560, 187556, 187552, 187550, 187537, 187536, 187535, 187534, 187531, 187510, 187508, 187505, 187489, 187488, 187487, 187486, 187485, 187484, 187482, 187435, 187434, 187432, 187426, 187343, 187341, 187340, 187339, 187338, 187335, 187203, 187202, 187201, 187198, 187193, 187152, 187151, 187150, 187149, 187148, 187147, 187146, 187145, 187143, 187136, 187133, 187117, 187084, 187081, 187064, 187047, 187046, 186994, 186992, 186990, 186989, 186987, 186981, 186980, 186969, 186967, 186966, 186965, 186962, 186939, 186938, 186937, 186926, 186859, 186857, 186855, 186853, 186851, 186845, 186844, 186843, 186838, 186834, 186816, 186815, 186814, 186813, 186811, 186809, 186807, 186805, 186694, 186693, 186692, 186690, 186689, 186688, 186668};
    //======

    const Int_t nrun = sizeof(runlist)/sizeof(Int_t);
    printf("nrun: %d\n", nrun);
    for (Int_t ind=0; ind<nrun; ind++) {
      plugin->AddRunNumber(runlist[ind]);
    }

    plugin->SetNrunsPerMaster(20);
    plugin->SetSplitMaxInputFileNumber(100);
  }
}

void Set12gESD(AliAnalysisAlien *plugin)
{
  plugin->SetGridDataDir("/alice/data/2012/LHC12g");
  //must be called before AddRunNumber!!
  plugin->SetRunPrefix("000");   // real data

  if(fkTest){
    //alice/data/2012/LHC12g/000188362/ESDs/pass2/12000188362001.10/root_archive.zip#AliESDs.root
    plugin->SetDataPattern("ESDs/pass2/12000188362001.10/AliESDs.root");
    plugin->AddRunNumber(188362);
    plugin->SetNrunsPerMaster(20); 
    plugin->SetSplitMaxInputFileNumber(100);
  }
  else {	
    plugin->SetDataPattern("ESDs/pass2/12000*.*/AliESDs.root");
 
    //http://alimonitor.cern.ch/configuration/index.jsp?partition=LHC12g&pass=2&s=%BB&raw_run=&filling_scheme=&filling_config=&fillno=&energy=&intensity_per_bunch=&mu=&interacting_bunches=&noninteracting_bunches_beam_1=&noninteracting_bunches_beam_2=&interaction_trigger=&rate=&beam_empty_trigger=&empty_empty_trigger=&muon_trigger=&high_multiplicity_trigger=&emcal_trigger=&calibration_trigger=&quality=&muon_quality=&comment=&field=&det_aco=&det_emc=&det_fmd=&det_hlt=&det_hmp=&det_mch=&det_mtr=&det_phs=&det_pmd=&det_spd=&det_sdd=&det_ssd=&det_tof=&det_tpc=&det_trd=&det_t00=&det_v00=&det_zdc=&hlt_mode=&changedon=
    //25 runs
    const Int_t runlist[]={188503, 188500, 188499, 188490, 188488, 188455, 188454, 188449, 188448, 188447, 188446, 188444, 188443, 188442, 188440, 188438, 188366, 188365, 188364, 188363, 188362, 188359, 188358, 188357, 188356};
    //======

    const Int_t nrun = sizeof(runlist)/sizeof(Int_t);
    printf("nrun: %d\n", nrun);
    for (Int_t ind=0; ind<nrun; ind++) {
      plugin->AddRunNumber(runlist[ind]);
    }

    plugin->SetNrunsPerMaster(20);
    plugin->SetSplitMaxInputFileNumber(100);
  }
}

AliAnalysisGrid* CreateAlienHandler(const char *taskname)
{
  AliAnalysisAlien *plugin = new AliAnalysisAlien();

  //========================================================================================
  //                      check
  //========================================================================================
 
  plugin->SetAPIVersion("V1.1x");
  plugin->SetROOTVersion("v5-34-01-1");
  plugin->SetAliROOTVersion("v5-03-50-AN");

  if(fProd=="10h"){
    Set10hESD(plugin);
  }
  else if(fProd=="10hMC"){
    Set10hMCESD(plugin);
  }
  else if(fProd=="11h"){
    Set11hESD(plugin);
  }
  else if(fProd=="12f"){
    Set12fESD(plugin);
  }
  else if(fProd=="12g"){
    Set12gESD(plugin);
  }
  else{
    printf("wrong fProd %s\n", fProd.Data());exit(1);
  }
  
  //========================================================================================
  //                       don't care
  //========================================================================================

  plugin->SetOverwriteMode();
  plugin->SetRunMode(fGridMode);
  plugin->SetMergeViaJDL(kTRUE);
  
  //tag will appear as function name, which can not have "-" !!
  const TString tag(Form("Prod%sID%d", fProd.Data(), fID));
  plugin->SetGridWorkingDir(Form("Analysis_%s",tag.Data()));
  plugin->SetGridOutputDir("output"); 
  plugin->SetAnalysisMacro(Form("analysis%s.C",tag.Data()));
  plugin->SetExecutable(Form("analysis%s.sh",tag.Data()));
  plugin->SetJDLName(Form("analysis%s.jdl",tag.Data()));

  plugin->SetAnalysisSource(Form("AliAnalysisTask%s.cxx", taskname));

  plugin->SetAdditionalLibs(Form("libGui.so libCore.so libTree.so libPhysics.so libMinuit.so libProof.so libmicrocern.so liblhapdf.so libpythia6.so libEG.so libGeom.so libVMC.so libEGPythia6.so libSTEERBase.so libESD.so libRAWDatabase.so libRAWDatarec.so libAOD.so libANALYSIS.so libANALYSISalice.so libCDB.so libSTEER.so libRAWDatasim.so libFASTSIM.so libEVGEN.so libAliPythia6.so libSTAT.so libhijing.so libTHijing.so libSTRUCT.so libPHOSUtils.so libPHOSbase.so libPHOSsim.so libPHOSrec.so libMUONcore.so libMUONmapping.so libMUONgeometry.so libMUONcalib.so libMUONraw.so libMUONtrigger.so libMUONbase.so libMUONsim.so libMUONrec.so libMUONevaluation.so libFMDbase.so libFMDsim.so libFMDrec.so libPMDbase.so libPMDsim.so libPMDrec.so libHMPIDbase.so libHMPIDsim.so libHMPIDrec.so libT0base.so libT0sim.so libT0rec.so libZDCbase.so libZDCsim.so libZDCrec.so libACORDEbase.so libACORDErec.so libACORDEsim.so libVZERObase.so libVZEROrec.so libVZEROsim.so libEMCALraw.so libEMCALUtils.so libEMCALbase.so libEMCALsim.so libEMCALrec.so libTPCbase.so libTPCrec.so libTPCsim.so libTPCfast.so libITSbase.so libITSsim.so libITSrec.so libTRDbase.so libTRDsim.so libTRDrec.so libTOFbase.so libTOFrec.so libTOFsim.so libHLTbase.so libHLTinterface.so libHLTsim.so libHLTrec.so libTENDER.so libTENDERSupplies.so libPWGPP.so\
 AliAnalysisTask%s.h AliAnalysisTask%s.cxx", taskname, taskname));

 
  return plugin;
}


int main(int argc, char * argv[])
{
  for(int ii=0; ii<argc; ii++){
    printf("%d: %s\n", ii, argv[ii]);
  }

  if(argc!=3){
    printf("argc!=3 should be ktest,gridmode like \"1 full\" \n");
    return 1;
  }

  //==========================================================================
  //            set from argv
  //==========================================================================

  return runPlugIn(atoi(argv[1]), argv[2]);
}

void Load()
{
  // load libraries (to be optimized)
  gSystem->Load("libCore.so");
  gSystem->Load("libTree.so");
  gSystem->Load("libPhysics");
  gSystem->Load("libMinuit");
  gSystem->Load("libProof");
  gSystem->Load("libmicrocern");
  gSystem->Load("liblhapdf");
  gSystem->Load("libpythia6");
  gSystem->Load("libEG");
  gSystem->Load("libGeom");
  gSystem->Load("libVMC");
  gSystem->Load("libEGPythia6");
  gSystem->Load("libSTEERBase");
  gSystem->Load("libESD");
  gSystem->Load("libCDB");
  gSystem->Load("libRAWDatabase");
  gSystem->Load("libRAWDatarec");
  gSystem->Load("libAOD");
  gSystem->Load("libANALYSIS");
  gSystem->Load("libANALYSISalice");
  gSystem->Load("libSTEER");
  gSystem->Load("libTENDER");
  gSystem->Load("libRAWDatasim");
  gSystem->Load("libFASTSIM");
  gSystem->Load("libEVGEN");
  gSystem->Load("libAliPythia6");
  gSystem->Load("libSTAT");
  gSystem->Load("libhijing");
  gSystem->Load("libTHijing");
  gSystem->Load("libSTRUCT");
  gSystem->Load("libPHOSUtils");
  gSystem->Load("libPHOSbase");
  gSystem->Load("libPHOSsim");
  gSystem->Load("libPHOSrec");
  gSystem->Load("libMUONcore");
  gSystem->Load("libMUONmapping");
  gSystem->Load("libMUONgeometry");
  gSystem->Load("libMUONcalib");
  gSystem->Load("libMUONraw");
  gSystem->Load("libMUONtrigger");
  gSystem->Load("libMUONbase");
  gSystem->Load("libMUONsim");
  gSystem->Load("libMUONrec");
  gSystem->Load("libMUONevaluation");
  gSystem->Load("libFMDbase");
  gSystem->Load("libFMDsim");
  gSystem->Load("libFMDrec");
  gSystem->Load("libPMDbase");
  gSystem->Load("libPMDsim");
  gSystem->Load("libPMDrec");
  gSystem->Load("libHMPIDbase");
  gSystem->Load("libHMPIDsim");
  gSystem->Load("libHMPIDrec");
  gSystem->Load("libT0base");
  gSystem->Load("libT0sim");
  gSystem->Load("libT0rec");
  gSystem->Load("libZDCbase");
  gSystem->Load("libZDCsim");
  gSystem->Load("libZDCrec");
  gSystem->Load("libACORDEbase");
  gSystem->Load("libACORDErec");
  gSystem->Load("libACORDEsim");
  gSystem->Load("libVZERObase");
  gSystem->Load("libVZEROrec");
  gSystem->Load("libVZEROsim");
  gSystem->Load("libEMCALraw");
  gSystem->Load("libEMCALUtils");
  gSystem->Load("libEMCALbase");
  gSystem->Load("libEMCALsim");
  gSystem->Load("libEMCALrec");
  gSystem->Load("libTPCbase");
  gSystem->Load("libTPCrec");
  gSystem->Load("libTPCsim");
  gSystem->Load("libTPCfast");
  gSystem->Load("libITSbase");
  gSystem->Load("libITSsim");
  gSystem->Load("libITSrec");
  gSystem->Load("libTRDbase");
  gSystem->Load("libTRDsim");
  gSystem->Load("libTRDrec");
  gSystem->Load("libTOFbase");
  gSystem->Load("libTOFrec");
  gSystem->Load("libTOFsim");
  gSystem->Load("libHLTbase");
  gSystem->Load("libHLTinterface");
  gSystem->Load("libHLTsim");
  gSystem->Load("libHLTrec");
  gSystem->Load("libPWGPP");
  
  // add aliroot include path
  gROOT->ProcessLine(Form(".include %s/include",
                          gSystem->ExpandPathName("$ALICE_ROOT")));
  
}

